package repository

import (
	"context"
	"gitee.com/DonHz/basic-go/webook/internal/repository/cache"
)

var (
	ErrCodeSendTooMany = cache.ErrCodeSendTooMany
	ErrCodeVerifyTooMany = cache.ErrCodeVerifyTooMany
)

type CodeRepository interface{
	Store(ctx context.Context, biz,phone,code string) error
	Verify(ctx context.Context, biz,phone,code string) (bool,error)
}

type CachedCodeRepository struct {
	cache cache.CodeCache
}

func NewCodeRepository(cache cache.CodeCache) CodeRepository {
	return &CachedCodeRepository{
		cache: cache,
	}
}

func (repo *CachedCodeRepository) Store(ctx context.Context, biz,phone,code string) error{
	return repo.cache.Set(ctx,biz,phone,code)
}

func (repo *CachedCodeRepository) Verify(ctx context.Context, biz,phone,code string) (bool,error) {
	return repo.cache.Verify(ctx,biz,phone, code)
}